<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('会员列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <form id="formId" class="form-inline">
            <input class="form-control mr-1" placeholder="会员名称" type="text" name="name"/>
            <a class="btn btn-primary btn-rounded mr-1" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
            <a class="btn btn-warning btn-rounded" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
        </form>
    </div>
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    $(function() {
        var options = {
            url: "/user/member/list.json",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            modalName: "会员",
            columns: [
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'name',
                    title: '会员'
                },
                {
                    field: 'title',
                    title: '类型'
                },
                {
                    field: 'price',
                    align: 'center',
                    title: '价钱',
                    formatter: function(value, row, index) {
                        return value / 100;
                    }
                },
                {
                    field: 'days',
                    title: '有效期',
                    formatter: function(value, row, index) {
                        return "购买后"+value+"天";
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info  btn-xs" href="javascript:void(0)" onclick="toFreeMember(\'' + row.id + '\')"><i class="fa fa-shopping-bag"></i> 赠送</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //赠送会员操作
    function toFreeMember(id) {
        var userId = [[${userId}]];
        $.modal.confirm("确定赠送会员吗?", function () {
            var data = {"userId": userId, "id": id};
            $.operate.submit("/user/member/free.json", "post", "json", data);
        });
    }
</script>
</body>
</html>